﻿using BaseData.API.Write.Applications.HospitalInformation.Command;
using BaseData.Domain.HospitalInformation;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace BaseData.API.Write.Applications.HospitalInformation.Commandhandler
{
    public class DepartmentsDelCommandHandler:IRequestHandler<DepartmentsDelCommand,ApiResult<int>>
    {
        IBaseRepository<Departments> repository;

        public DepartmentsDelCommandHandler(IBaseRepository<Departments> repository)
        {
            this.repository = repository;
        }

        public async Task<ApiResult<int>> Handle(DepartmentsDelCommand request, CancellationToken cancellationToken)
        {
            var res=repository.GetAll().FirstOrDefault(x=>x.DepartmentId==request.DepartmentId);
            res.Isdelete = true;
            await repository.UpdateAsync(res);
            return new ApiResult<int>()
            {
                Message = ApiEnum.删除成功.ToString(),
                Code = ApiEnum.删除成功,
            };

        }
    }
}
